<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        const dogs = [
            { weight: 22, curFood: 250, owners: ['Alice', 'Bob'] },
            { weight: 8, curFood: 200, owners: ['Matilda'] },
            { weight: 13, curFood: 275, owners: ['Sarah', 'John'] },
            { weight: 32, curFood: 340, owners: ['Michael'] }
        ];

        // #1
        dogs.forEach(dog => {
            dog.recFood = Math.trunc(dog.weight ** 0.75 * 28);
        });

        // #2
        const dogSarah = dogs.find(dog => dog.owners.includes('Sarah'));
        console.log(`Sarah's dog is eating too ${dogSarah.curFood > dogSarah.recFood ? 'much' : 'little'}`);

        // #3
        const ownersEatTooMuch = dogs
            .filter(dog => dog.curFood > dog.recFood)
            .flatMap(dog => dog.owners);

        const ownersEatTooLittle = dogs
            .filter(dog => dog.curFood < dog.recFood)
            .flatMap(dog => dog.owners);

        // #4
        console.log(`${ownersEatTooMuch.join(' and ')}'s dogs eat too much`);
        console.log(`${ownersEatTooLittle.join(' and ')}'s dogs eat too little`);

        //#5
        console.log(dogs.some(dog => dog.curFood === dog.recFood));

        // #6
        checkEat = dog => dog.curFood > dog.recFood * 0.9 && dog.curFood < dog.recFood * 1.1;

        console.log(dogs.some(checkEat));

        // #7
        console.log(dogs.filter(checkEat));

        // #8
        const sortList = dogs.slice().sort((a, b) => a.recFood - b.recFood);
        console.log(sortList);
    </script>
</body>

</html>